$Title Test: Sec-Eq model, loop over the non-prod value of land given a capital distr

$Offsymxref Offsymlist

* COUENNE chosen for solving a problem of mixed integers
Option MINLP = COUENNE;

Option Limrow=0, Limcol=0;
Option Solprint=Off;
$Offsymxref
$Offsymlist

$Ontext
This sector-level equilibrium model is the baseline model for quantifying
efficiency loss due to the non-prod value of farmland. The model aims to track
the changes in econ efficiency, productivity of land and labor, distr of land,
and the allocation of labor when the non-prod value of farmland increases.

Basic logic of the model is this:

There are 51 households in the semi-closed economy. They are endowed with the
same amounts of land (s0) and labor (l0), but have different endowments
in capital. The capital distr is taken as given as no credit mkt is available.

In the beginning, all households have limited land which they could cultivate
at a low efficiency level (i.e., tech efficiency of a). By using the capital to
rent in land and hire farm labor, a household could expand its cultivaiton size
beyond 30 units, becoming a large farm. A large farm enjoys a higher
tech efficiency of a2. Land market is local and clears at the eqquilibrium.

Households are free to allocate labor in farm and nonfarm sectors. Labor market
of this economy is integrated to others. The wage rates equalize across sectors.

By cultivating its own land, a household not
only makes farming income, but also obtains the non-prod value of land
(i.e., farmland services safety-net and appreciate-asset functions).

The hh objective is to maximize the total income, including the non-prod
value. The marginal the non-prod value of land is denoted by v.

The problem of multi-hh income-maximizing is transformed into a social planner
problem by assuming frictionless factor markets. The social planner maximize
the total income of the economy.

Table 4 and figure 1 in the article can be replicated using this program

$Offtext

****************Setup the village economy of five households ******************

Sets

h    Households
             /1*51/;


*************************Multipliers and endownments ***************************

Scalars

** All monetary values are measured in 1,000
** All labor measured in months and land in mu

n    No. households in the economy
     /51/

m    Capital multiplier
     /19.8142/

a    Tech eff for small farms
     /2.3/

a2   Tech eff large farms
     /4.4/

k    Setup cost for small farms per mu
     /0.8/

k2   Setup cost for large farms per mu
     /1.1/

s0   HH land endowment
     /4.1/

l0   HH labor endowment (# labor-months of three laborers)
     /14.1/

f    Multiplier for the min labor-month input to cultivate each unit of land
     /0.3/

rho  Multiplier for supervision labor-month
     /0.1/

int  Exogenous interest rate for bank savings
     /0.004/

w   Exogenous nonfarm and farm wage rate
    /2.5/

;

********************************Capital endowment ******************************

Parameters

c(h) Capital endowment for each household;

* Enter the location of parameter files
* "c_5" is a particular distribution of capital endowments
$ Call gdxxrw C:/Users/Documents/gamsdir/projdir/Parameters/c_5.xls par=c rng=Sheet1!A1 rdim=1
$ gdxin c_5.gdx
$ Load  c
$ gdxin

Display c;

Parameters
v(h) Property value multiplier;

* Enter the location of parameter files
* %instance%: loop over numbers
* need to create a separate "run" file and a "makerun" file
$ Call gdxxrw C:/Users/Documents/gamsdir/projdir/Parameters/v_%instance%.xls par=v rng=Sheet1!A1 rdim=1
$ gdxin v_%instance%.gdx
$ Load  v
$ gdxin

Display v;

***************************Target variables ************************************

Variables

** Variables with "2" are those for large farms
** The income is the expected value for reasons explained in the paper

einc      Economy-level total expected income to be maximized

inc(h)    HH expected income

pinc(h)   HH productive income

s(h)      HH cultivated size

s2(h)     HH cultivated size for large farms

sab       Economy land abandonment

lf(h)     HH labor invested in farming

lf2(h)    HH labor invested in farming for large farms

lnf(h)    HH labor invested in nonfarm activities

lnf2(h)   HH labor invested in nonfarm activities for large farms

hin(h)    HH amount of hired-in farming labor

hin2(h)   HH amount of hired-in farming labor for large farms

hout(h)   HH amount of hired-out farming labor

hout2(h)  HH amount of hired-out farming labor for large farms

lg(h)     HH dummy variable equal one if a farm expands beyoud 30

md(h)     HH dummy variable equal one if a farm is s0-30 in size

ex(h)     HH dummy variable equal one if a hh reduces s(h) to zero

fu        Economy dummy variable equal one if any land is abandoned

r         Endog land rental rate
;

Positive variables
s, lf, lnf, hin, hout, s2, lf2, lnf2, hin2, hout2, sab, r;

** HH has to choose whether to exit farming and the farm-size type
** Economy has to choose whether any land should be abandoned

Binary variables
lg, md, ex, fu ;

***************************Target HH functions *********************************

Equations

Obj          Economy-level total expected income

Constr01(h)  HH income definition

Constr02(h)  HH productive income definition

Constr1(h)   Farming labor constraint

Constr21(h)  Farming labor constraint 1

Constr22(h)  Farming labor constraint 2

Constr23(h)  Farming labor constraint 3

Constr3(h)   Budget constraint

Constr41(h)  Farm type option 1

Constr42(h)  Farm type option 2

Constr43(h)  Farm type option 3

Constr44(h)  Farm type option 4

Constr45(h)  Farm type option 5

Constr51(h)  Farm type option size requirement 1

Constr52(h)  Farm type option size requirement 2

Constr53(h)  Farm type option size requirement 3

Constr54(h)  Farm type option size requirement 4

Constr55(h)  Farm type option size requirement 5

Constr56(h)  Farm type option size requirement 6

Constr57(h)  Farm type option size requirement 7

Constr58(h)  Farm type option size requirement 8

Constr59(h)  Farm type option size requirement 9

MktConstr1   Market clearance condition for land

MktConstr21  Market clearance condition for rental rate

MktConstr22  Market clearance condition for rental rate

MktConstr23  Market clearance condition for rental rate

MktConstr24  Market clearance condition for rental rate ;

** The social planner's obj function is the sum of household incomes

Obj..
einc =E= Sum(h,inc(h));

** HH income, incl the non-prod value of land

Constr01(h)..
inc(h) =E=

w*lnf(h) * (1-lg(h))
 + w*lnf2(h) * lg(h)

+ a*sqrt(lf(h)+hin(h))*sqrt(s(h))*(1-lg(h))
+ a2*sqrt(lf2(h)+hin2(h))*sqrt(s2(h))*lg(h)

+ v(h)*sqrt(lf(h)+hin(h))*sqrt(s(h)) * (1-md(h))
+ v(h)*sqrt((lf(h)+hin(h))/(0.01+s(h))*s0)*sqrt(s0) * md(h)
+ v(h)*sqrt((lf2(h)+hin2(h))/(0.01+s2(h))*s0)*sqrt(s0) * lg(h)

+ w*hout(h) * (1-lg(h))
+ w*hout2(h) * lg(h)

- w*hin(h) * (1-lg(h))
- w*hin2(h) * lg(h)

- r*(s(h)-s0) * (1-lg(h))
- r*(s2(h)-s0) * lg(h)

- k*s(h) * (1-lg(h))
- k2*s2(h) * lg(h)

+ int* ( m * c(h)
- (r*(s(h)-s0) + k * s(h)) * (1-lg(h))
- (r*(s2(h)-s0) + k2 * s2(h)) * lg(h)) ;

** HH productiion income

Constr02(h)..

pinc(h) =E=

w*lnf(h) * (1-lg(h))
 + w*lnf2(h) * lg(h)

+ a*sqrt(lf(h)+hin(h))*sqrt(s(h))*(1-lg(h))
+ a2*sqrt(lf2(h)+hin2(h))*sqrt(s2(h))*lg(h)

+ w*hout(h) * (1-lg(h))
+ w*hout2(h) * lg(h)

- w*hin(h) * (1-lg(h))
- w*hin2(h) * lg(h)

- r*(s(h)-s0) * (1-lg(h))
- r*(s2(h)-s0) * lg(h)

- k*s(h) * (1-lg(h))
- k2*s2(h) * lg(h)

+ int* ( m * c(h)
- (r*(s(h)-s0) + k * s(h)) * (1-lg(h))
- (r*(s2(h)-s0) + k2 * s2(h)) * lg(h)) ;


** HH farming labor equals labor endowment minus other labor use
* HH labor is used up

Constr1(h)..

(lnf(h) + hout(h) + rho*hin(h)+lf(h)) * (1-lg(h))
+ (lnf2(h) + hout2(h) + rho*hin2(h) + lf2(h)) * lg(h)

=E= l0 ;

** HH farming labor no less than minimum requirement

Constr21(h)..

(lf(h)+ hin(h))* (1-lg(h))
+ (lf2(h)+ hin2(h))* lg(h) =G=
f*s(h) * (1-lg(h))
+ f*s2(h) * lg(h) ;

* HH cannot hire in and hire out simultaneously

Constr22(h)..

hout(h)* hin(h)
+ hout2(h)* hin2(h) =E= 0 ;

* HH cannot hire in and work off-farm simult for the same wage across sectors

Constr23(h)..

lnf(h)* hin(h)
+ lnf2(h)* hin2(h) =E= 0 ;

* Captial expenditure is constrained by the endowment

Constr3(h)..

(r*(s(h)-s0) + k*s(h) + w*hin(h)) * (1-lg(h))
+ (r*(s2(h)-s0) + k2*s2(h)+ w*hin2(h))* lg(h)
=L= m*c(h) ;

** Variables with "2" and those w/o "2" cannot co-exist

Constr41(h)..  s(h)*lg(h) + s2(h)*(1-lg(h)) =E= 0 ;

Constr42(h)..  lf(h)*lg(h) + lf2(h)*(1-lg(h)) =E= 0 ;

Constr43(h)..  hin(h)*lg(h) + hin2(h)*(1-lg(h)) =E= 0 ;

Constr44(h)..  hout(h)*lg(h) + hout2(h)*(1-lg(h)) =E= 0 ;

Constr45(h)..  lnf(h)*lg(h) + lnf2(h)*(1-lg(h)) =E= 0 ;

** Not allowing for s or s2=30 to avoid confusion

Constr51(h)..  (s(h)-29.99)*(1-lg(h)) =L= 0 ;

Constr52(h)..  (s2(h)-30.01)*lg(h) =G= 0 ;

* The smallest farming size is 1 unit

Constr53(h)..  s(h) * ex(h) =E= 0 ;

Constr54(h)..  (s(h)-1.01) * (1-ex(h)) =G= 0 ;

Constr55(h)..  lf(h) * ex(h) =E= 0 ;

Constr56(h)..  hin(h) * ex(h) =E= 0 ;

* The middle sized farms in s0-30

Constr57(h)..  (s(h) - s0) * (1 - md(h)) =L= 0 ;

Constr58(h)..  (s(h) - s0 - 0.01) * md(h) =G= 0 ;

Constr59(h)..  (s(h) - 29.99) * md(h) =L= 0 ;

*Total land used less or equal to the land endowment

MktConstr1.. sab =E= s0*n - Sum(h, s(h))- Sum(h, s2(h))  ;

** Land rental rate should be zero is there is land abandoned

MktConstr21.. (sab-0.1) * fu =L=0 ;

MktConstr22.. -(sab-0.1) * (1-fu) =L=0 ;

MktConstr23..  r * (1-fu) =E=0 ;

MktConstr24.. (r-0.15) * fu =G=0 ;

******************************Define the model *********************************

Model Test /All/;

******************************Solve the model **********************************

** Set initial values
lg.l('51') = 1;
s2.l('51') = 70;
fu.l=1;
sab.l = 0.01;

** Setup upper bound for the rental rate
r.up = 0.6;

** Solve mixed integer nonlinear program
Solve Test using MINLP maximizing einc;

** Export result to Excel
execute_unload 'SE_Baseline-%instance%.gdx';
execute 'gdxxrw.exe SE_Baseline-%instance%.gdx o=SE_V13-%instance%.xls var=einc.l rng=A1 var=inc.l rng=A2 var=pinc.l rng=A4 var=s.l rng=A7 var=md.l rng=A9 var=s2.l rng=A10 var=lf.l rng=A13 var=lf2.l rng=A16 var=lnf.l rng=A19 var=lnf2.l rng=A22 var=hin.l rng=A25 var=hin2.l rng=A28 var=hout.l rng=A31 var=hout2.l rng=A34 var=r.l rng=A36 var=sab.l rng=A38 var=fu.l rng=A39';




